const newsData = {
  cates: 0,
  page: 1,
  getData: function () {
    ajax_get(
      host + `/api/news`,
      true,
      {},
      (res) => {
        if (res.code === 0) {
          const { banner, news } = res.data;
          $(".banner-txt span:nth-child(1)").text(
            banner.title ? banner.title : ""
          );
          $(".banner-txt span:nth-child(2)").text(
            banner.content ? banner.content : ""
          );
          let targetUrl = `url(${banner.path}) no-repeat;background-size: cover;`;
          $(".banner").attr("style", `background:${targetUrl}`);
          // 内容区
          $(".news-tabs .news-tab").eq(0).html(news.company.cate_title);
          $(".news-tabs .news-tab").eq(1).html(news.industry.cate_title);
          // $('.news-container ')
          let str = ``;
          if (news.company && news.company.list.length > 0) {
            news.company.list.forEach((item, index) => {
              str += `
              <div class="news-list wow fadeInDown animated" data-id="${
                item.id
              }" data-wow-delay=".18s">
                  <a href="newsDetail.html?id=${item.id}">
                    <div class="news-index">${
                      index > 10 ? index : "0" + (index + 1)
                    }</div>
                    <div class="news-title">${item.title}</div>
                    <div class="news-date">${item.up_date}</div>
                    <div class="news-desc">${item.description}</div>
                    <div class="news-img">
                        <img src="${item.img}" alt="">
                    </div>
                  </a>
              </div>
              `;
            });
          }
          $(".news-core .news-container:nth-child(1)").html(str);
          let str2 = ``;
          if (news.industry && news.industry.list.length > 0) {
            news.industry.list.forEach((item, index) => {
              str2 += `
              <div class="news-list wow fadeInDown animated" data-id="${
                item.id
              }" data-wow-delay=".18s">
              <a href="newsDetail.html?id=${item.id}">
                <div class="news-index">${
                  index > 10 ? index : "0" + (index + 1)
                }</div>
                    <div class="news-title">${item.title}</div>
                    <div class="news-date">${item.up_date}</div>
                    <div class="news-desc">${item.description}</div>
                    <div class="news-img">
                        <img src="${item.img}" alt="">
                    </div>
                  </a>
              </div>
              `;
            });
          }
          $(".news-core .news-container:nth-child(2)").html(str2);
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
};

const cpdData = {
  cates: 0,
  page: 1,
  getData: function () {
    ajax_get(
      host + `/api/cpd`,
      true,
      {},
      (res) => {
        if (res.code === 0) {
          const { banner, model1, model2 } = res.data;
          $(".banner-txt span:nth-child(1)").text(
            banner.title ? banner.title : ""
          );
          $(".banner-txt span:nth-child(2)").text(
            banner.content ? banner.content : ""
          );
          let targetUrl = `url(${banner.path}) no-repeat;background-size: cover;`;
          $(".banner").attr("style", `background:${targetUrl}`);
          // 内容区
          $(".section-bg .section-title").text(model1.title);
          $(".section-bg .section-desc").text(model1.content);
          $(".section-list .section-list-box:nth-child(1) span").text(
            model1.img1_title
          );
          $(".section-list .section-list-box:nth-child(2) span").text(
            model1.img2_title
          );
          $(".section-list .section-list-box:nth-child(3) span").text(
            model1.img3_title
          );
          $(".section-list .section-list-box:nth-child(4) span").text(
            model1.img4_title
          );
          $(".section-list .section-list-box:nth-child(1) img").attr(
            "src",
            model1.img1
          );
          $(".section-list .section-list-box:nth-child(2) img").attr(
            "src",
            model1.img2
          );
          $(".section-list .section-list-box:nth-child(3) img").attr(
            "src",
            model1.img3
          );
          $(".section-list .section-list-box:nth-child(4) img").attr(
            "src",
            model1.img4
          );
          $(".sectin-bg2 .section-title").text(model2.title);

          let str = ``;
          if (model2.data && model2.data.length > 0) {
            const listArr = model2.data.map((item) => {
              item.description = getHtmlStr(item.description);
              return item;
            });
            listArr.forEach((item) => {
              str += `
                  <div class="recruitment-box">
                  <div class="recruitment-title">
                      <span>${item.job} </span>
                      <span>${item.salary}</span>
                      <span>${item.education}</span>
                      <span>${item.seniority}</span>
                      <img src="./images/down.png" alt="">
                  </div>
                  <div class="recruitment-detail">
                      <div class="detail-more">
                        <span>${item.education}</span>
                        <span>${item.seniority}</span>
                      </div>
                      <span>DESCRIPTION</span>
                      <div class='detail-content'>
                        ${item.description}
                      </div>
                      <div class="recruitment-btn">
                          联系我们
                      </div>
                  </div>
              </div>
                  `;
            });
            $(".section-recruitment").html(str);
          }

          // $(".section-bg3 .section-desc").text()
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
};

const edrSystem = {
  cates: 0,
  page: 1,
  getData: function () {
    ajax_get(
      host + `/api/edr`,
      true,
      {},
      (res) => {
        if (res.code === 0) {
          const { banner, model1, model2 } = res.data;
          $(".banner-txt span:nth-child(1)").text(
            banner.title ? banner.title : ""
          );
          $(".banner-txt span:nth-child(2)").text(
            banner.content ? banner.content : ""
          );
          let targetUrl = `url(${banner.path}) no-repeat;background-size: cover;`;
          $(".banner").attr("style", `background:${targetUrl}`);
          // 内容区
          $(".edrsystem-title").text(model1.title.title);
          $(".edrsystem-txt").text(model1.title.content);

          let str = ``;
          let titleStr = ``;
          if (model1 && model1.data.length > 0) {
            model1.data.forEach((item, index) => {
              if (index === 0) {
                str += `
                    <div class="edr-detail cur">
                        <div class="edr-bg"></div>
                        <img src="${item.img}" alt="">
                        <div class="edr-detail-title">
                          ${item.content}
                        </div>
                    </div>
                  `;
                titleStr += `
                <div class="edr-cate cur">
                    <span>${item.title}</span>
                </div>
                `;
              } else {
                str += `
                  <div class="edr-detail">
                      <div class="edr-bg"></div>
                      <img src="${item.img}" alt="">
                      <div class="edr-detail-title">
                        ${item.content}
                      </div>
                  </div>
                `;
                titleStr += `
                <div class="edr-cate ">
                    <span>${item.title}</span>
                </div>
                `;
              }
            });
            $(".edrsystem-desc").html(str);
            $(".edrsystem-cate").html(titleStr);

            $(".pro-footer .pro-desc").text(model2.content);
            $(".pro-footer .pro-btn a").text(model2.button);
          }
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
};

const productData = {
  cates: 0,
  page: 1,
  getData: function () {
    ajax_get(
      host + `/api/products`,
      true,
      {},
      (res) => {
        if (res.code === 0) {
          const { banner, model1, model2 } = res.data;
          $(".banner-txt span:nth-child(1)").text(
            banner.title ? banner.title : ""
          );
          $(".banner-txt span:nth-child(2)").text(
            banner.content ? banner.content : ""
          );
          let targetUrl = `url(${banner.path}) no-repeat;background-size: cover;`;
          $(".banner").attr("style", `background:${targetUrl}`);
          // 内容区
          $(".pro-title").text(model1.title);
          if (model1.data && model1.data.length > 0) {
            let str = ``;
            model1.data.forEach((item) => {
              str += `
                <div class="pro-box wow fadeInDown" data-wow-delay=".11s">
                <div class="pro-img">
                    <img src="${item.img}" alt="">
                </div>
                <div class="pro-txt">
                    <span>${item.title}</span>
                    <div>
                      ${item.content}
                    </div>
                </div>
            </div>
                `;
            });

            $(".pro-content").html(str);
          }
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
};

const aboutUsData = {
  cates: 0,
  page: 1,
  getData: function () {
    ajax_get(
      host + `/api/aboutUs`,
      true,
      {},
      (res) => {
        if (res.code === 0) {
          const { banner, model1, model2, model3 } = res.data;
          $(".banner-txt span:nth-child(1)").text(
            banner.title ? banner.title : ""
          );
          $(".banner-txt span:nth-child(2)").text(
            banner.content ? banner.content : ""
          );
          let targetUrl = `url(${banner.path}) no-repeat;background-size: cover;`;
          $(".banner").attr("style", `background:${targetUrl}`);
          // 内容区
          $(".section-bg1 .section-title").text(model1.title.title);
          $(".section-bg1 .section-desc").text(model1.title.content);
          $(".section-bg2 .section-title").text(model2.title);
          $(".section-bg2 .section-desc").text(model2.content);
          $(".section-bg3 .section-title").text(model3.title);
          $(".section-bg3 .section-sub-title").text(model3.title_s);
          $(".section-bg3 .section-desc").text(model3.content);
          let str = ``;
          if (model1.data && model1.data.length > 0) {
            model1.data.forEach((item) => {
              str += `
                <div class="section-img-box">
                    <img src="${item.img}" alt="">
                    <span>${item.title}</span>
                </div>  
                `;
            });
          }
          $(".section-img").html(str);
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
};

const indexData = {
  cates: 0,
  page: 1,
  getData: function () {
    ajax_get(
      host + `/api/index`,
      true,
      {},
      (res) => {
        if (res.code === 0) {
          const { banner, model1, model2, model3, model4, model5 } = res.data;
          // banner
          let str = ``;
          if (banner && banner.length > 0) {
            banner.forEach((item) => {
              let imgUrl = `background: url('${item.path}') center center / 100% 100% no-repeat`;
              str += `
              <div class="nest-full" style="${imgUrl}">
                  <span class="wow fadeInDown animated">${item.title}</span>
                  <span class="wow fadeInDown animated">${item.content}</span>
                  <div class="btn wow fadeInDown animated"><a href="cpd.html">${item.button}</a></div>
              </div>
                `;
            });
          }
          $(".about-img img").attr("src", model1.img);
          $(".about-container .about-desc>span").text(model1.title);
          $(".about-container .about-desc>p").html(model1.content);
          $(".nest-full-box").html(str);

          // 内容区
          $(".main-content .box-title").text(model2.title.title);
          let proStr = "";
          if (model2.data && model2.data.length > 0) {
            model2.data.forEach((item) => {
              proStr += `
              <div class="pro-box" data-url="${item.img}">
                  <img src="${item.icon}" alt="">
                  <span>${item.title}</span>
              </div>
              `;
            });
          }
          $(".main-content .box-content").html(proStr);

          let fullBg = [
            [
              "./images/banner1.png",
              "./images/banner1.png",
              "./images/banner1.png",
            ],
            "./images/bg1.png",
            (model2.data && model2.data[0].img) || "./images/bg2.png",
            model3.img || "./images/cpd-bg.png",
            "#fff",
            "#edfbff",
            "#26678f",
          ];
          fullBg[0] = banner.map((item) => {
            return item.path;
          });
          getBanner(fullBg);
          $(".cpd-container .box-title").text(model3.title);
          $(".cpd-container .box-content p").text(model3.content);
          $(".edr-container .box-title").text(model4.title);
          $(".edr-container .box-content p").text(model4.content);
          let edrStr = "";
          edrStr += `
          <div class="list-box">
                <img src="${model4.edr1_img}" alt="">
                <span>${model4.edr1_title}</span>
            </div>
            <div class="list-box">
                <img src="${model4.edr2_img}" alt="">
                <span>${model4.edr2_title}</span>
            </div>
            <div class="list-box">
                <img src="${model4.edr3_img}" alt="">
                <span>${model4.edr3_title}</span>
            </div>
          `;
          $(".edr-container .box-list").html(edrStr);

          let newsStr = "";
          newsStr += `
          <div class="news-box cur">
              <img src="${model5.news1_img}" alt="">
              <div class="news-date">
                  <span>${model5.news1_date[0]}</span>
                  <span>${model5.news1_date[1]}/${model5.news1_date[2]}</span>
              </div>
              <div class="news-content">
               ${model5.news1_title}
              </div>
          </div>
          <div class="news-box">
              <img src="${model5.news2_img}" alt="">
              <div class="news-date">${model5.news2_date}</div>
              <div class="news-content">
              ${model5.news2_title}
              </div>
          </div>
          <div class="news-box">
              <img src="${model5.news3_img}" alt="">
              <div class="news-date">${model5.news3_date}</div>
              <div class="news-content">
              ${model5.news3_title}
              </div>
          </div>
          <div class="news-box">
              <img src="${model5.news4_img}" alt="">
              <div class="news-date">${model5.news4_date}</div>
              <div class="news-content">
              ${model5.news4_title}
              </div>
          </div>

          `;
          $(".news-left").html(newsStr);
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
};

// 详情配置 请查看js文件 头部
function getBanner(fullBg) {
  let innerWidth = window.innerWidth;
  if (innerWidth >= 1200) {
    $(".fullPage").fullScreen({
      scrollBar: true,
      resize: true,
      autoScrolling: false,
      // fullBg: [['./images/banner1.png', './images/banner1.png', './images/banner1.png'], './images/bg1.png', './images/bg2.png', './images/cpd-bg.png', '#fff', '#40c29e54','#26678f'],
      fullBg: fullBg,
      navTip: ["第一屏", "第二屏", "第三屏", "第四屏", "第五屏", "第六屏"],
      startCallback: function (next,index) {
        if(next !== 7){
           // 加载wow动画
          wow = new WOW({
            animateClass: "animated",
          });
          wow.init();
        }
      },
      endCallback: function (prev, index, direction) {
        // 这一段解决wow的兼容问题
        $(".full-box .full")
          .eq(prev - 1)
          .find(".wow")
          .each(function () {
            if ($(this).attr("data-wow-delay")) {
              $(this).attr(
                "style",
                "animation-delay:" + $(this).attr("data-wow-delay")
              );
            } else {
              $(this).attr("style", "");
            }
          });
        $(".full-box .full")
          .eq(prev - 1)
          .find(".wow")
          .addClass("animated");
        // 结束
      },
    });
  } else if (innerWidth >= 992) {
    $(".fullPage").fullScreen({
      scrollBar: true,
      resize: true,
      autoScrolling: false,
      fullBg: [
        [
          "./images/banner1.png",
          "./images/banner1.png",
          "./images/banner1.png",
        ],
        "./images/bg1.png",
        "./images/bg2.png",
        "./images/cpd-bg.png",
        "#fff",
        "#40c29e54",
        "#26678f",
      ],
      navTip: ["第一屏", "第二屏", "第三屏", "第四屏", "第五屏", "第六屏"],
      startCallback: function (next,index) {
        if(next !== 7){
           // 加载wow动画
          wow = new WOW({
            animateClass: "animated",
          });
          wow.init();
        }
      },
      endCallback: function (prev, index, direction) {
        // 这一段解决wow的兼容问题
        $(".full-box .full")
          .eq(prev - 1)
          .find(".wow")
          .each(function () {
            if ($(this).attr("data-wow-delay")) {
              $(this).attr(
                "style",
                "animation-delay:" + $(this).attr("data-wow-delay")
              );
            } else {
              $(this).attr("style", "");
            }
          });
        $(".full-box .full")
          .eq(prev - 1)
          .find(".wow")
          .addClass("animated");
        // 结束
      },
    });
  } else {
    $(".fullPage").fullScreen({
      scrollBar: true,
      resize: true,
      autoScrolling: false,
      fullBg: [
        [
          "./images/banner1.png",
          "./images/banner1.png",
          "./images/banner1.png",
        ],
        "./images/bg1.png",
        "./images/bg2.png",
        "./images/cpd-bg.png",
        "#fff",
        "#40c29e54",
        "#26678f",
      ],
      navTip: ["第一屏", "第二屏", "第三屏", "第四屏", "第五屏", "第六屏"],
      startCallback: function (next,index) {
        if(next !== 7){
           // 加载wow动画
          wow = new WOW({
            animateClass: "animated",
          });
          wow.init();
        }
      },
      endCallback: function (prev, index, direction) {
        // 这一段解决wow的兼容问题
        $(".full-box .full")
          .eq(prev - 1)
          .find(".wow")
          .each(function () {
            if ($(this).attr("data-wow-delay")) {
              $(this).attr(
                "style",
                "animation-delay:" + $(this).attr("data-wow-delay")
              );
            } else {
              $(this).attr("style", "");
            }
          });
        $(".full-box .full")
          .eq(prev - 1)
          .find(".wow")
          .addClass("animated");
        // 结束
      },
    });
  }
}


const newsDetails = {
  cates: 0,
  page: 1,
  getData: function () {
    ajax_get(
      host + `/api/news/details?id=${GetQueryString('id')}`,
      true,
      {},
      (res) => {
        if (res.code === 0) {
          const {details,next,prev,recommend} = res.data
          $('.detail-title').text(details.title)
          $('.detail-desc>div:nth-child(1) span').text(details.status)
          $('.detail-desc>div:nth-child(2) span').text(details.up_date)
          $('.detail-main').html(getHtmlStr(details.content))
          let prevStr = ''
          let nextStr = ''
          if(prev){
            prevStr = `
            <div class="detail-page-prev">上一篇：<a href="newsDetail.html?id=${prev.id}">${prev.title}</a></div>
            `
          }
          if(next){
            nextStr = `
            <div class="detail-page-prev">下一篇：<a href="newsDetail.html?id=${next.id}">${next.title}</a></div>
            `
          }
          $('.detail-page').html(prevStr +  nextStr)
          
          let recommendStr = ''
          if(recommend && recommend.length > 0) {
            recommend.forEach(item=>{
              recommendStr += `
              <div class="hot-news-list">
                <a href="newsDetail.html?id=${item.id}">
                  <span>${item.title}</span>
                </a>
              </div>
              `
            })
          }
          $('.detail-list').html(recommendStr)
        
        }
      },
      (err) => {
        console.log(err);
      }
    );
  },
};